package com.sanjiahantang.ythshopping.presenter;

import android.content.Context;
import android.util.Log;

import com.sanjiahantang.ythshopping.config.ConfigValue;
import com.sanjiahantang.ythshopping.http.BaseDelegate;
import com.sanjiahantang.ythshopping.http.ExceptionHelper;
import com.sanjiahantang.ythshopping.http.OkHttpClientManager;
import com.sanjiahantang.ythshopping.model.SqOrderMsg;
import com.sanjiahantang.ythshopping.utils.Utils;
import com.sanjiahantang.ythshopping.views.SqPayMessageView;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by admin on 2017/6/8.
 */

public class SqPayMessagePresenter extends BasePresenter {
    SqPayMessageView sqpaymessageview;

    public SqPayMessagePresenter(SqPayMessageView sqpaymessageview) {this.sqpaymessageview=sqpaymessageview;}

    public void getSqOrderMsg(final Context context, String sid, String price)
    {
        initLoadDialog(context);
        mLoadingDialog.show();
        Map<String,String> params=new HashMap<>();
        params.put("key", ConfigValue.DATA_KEY);
        params.put("pay_money",price);
        params.put("sid",sid);
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "scan/getPayInfo", params, new BaseDelegate.ResultCallback<SqOrderMsg>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                dismiss();
                Utils.showToast(context, ExceptionHelper.getMessage(e, context));
                Log.e("SqPayMessageError", "onError: " + e.getMessage());

            }

            @Override
            public void onResponse(SqOrderMsg response, Object tag) {
                dismiss();
                sqpaymessageview.getPayMessage(response);
                Log.e("SqPayMessage", "onError: " + response.getData().toString());

            }
        },true);



    }

}
